
// js对象转url
export const obj2url = (obj) => {
  if (!obj) return ''
  let params = [];
  Object.entries(obj).forEach(([key, val]) => {
    if (val === 0 || val) params.push(encodeURIComponent(key) + "=" + encodeURIComponent(val))
  })
  return params.join("&")
}

// 生成指定长度的随机字符串
export const randomStr = (range) => {
  let baseStr = 'AaBbCcDdEeFfGgHhiJjKkLlMmNnPpQqRrSsTtUuVvWwXxYyZz9876543210'
  let str = '', num = 0, len = baseStr.length
  for (num = 0; num < range; num++) {
    str += baseStr.charAt(Math.floor(Math.random() * len))
  }
  return str
}